package com.xiyu.service.service.customer;

import com.xiyu.service.model.customer.contact.CustomerContactMail;
import com.xiyu.service.repository.customer.contact.CustomerContactMailRepository;
import com.xiyu.service.service.system.user.UserService;
import com.xiyu.service.vo.customer.customerContact.CustomerContactPageQueryMailOutput;
import com.xiyu.service.vo.customer.customerContact.CustomerContactPageQueryMailInput;
import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.babyfish.jimmer.Page;
import java.util.*;

import com.xiyu.service.framework.web.web.core.pojo.PageResult;
import com.xiyu.service.convert.customer.CustomerContactConvert;

import static com.xiyu.service.framework.exception.util.ServiceExceptionUtil.exception;
import static com.xiyu.service.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;

/**
 * 客户联系人 Service 实现类
 */
@Service
@Validated
public class CustomerContactServiceImpl implements CustomerContactService {

    @Resource
    private CustomerContactMailRepository customerContactMailRepository;

    @Resource
    private UserService userService;




    @Override
    public PageResult<CustomerContactPageQueryMailOutput> pageQueryMail(CustomerContactPageQueryMailInput inputVO) {
        List<Long> ownerUserIds = userService.getOwnerUserIds(getLoginUserId());
        Page<CustomerContactMail> pageCustomerContactMail = customerContactMailRepository.pageQueryMail(inputVO, ownerUserIds);
        List<CustomerContactPageQueryMailOutput> listCustomerContactMail = CustomerContactConvert.INSTANCE.pageQueryMailOutputConvert(pageCustomerContactMail.getRows());
        return new PageResult<>(listCustomerContactMail, pageCustomerContactMail.getTotalRowCount());
    }

}
